<template>
  <el-table :data="list" border fit stripe highlight-current-row style="width: 100%;margin: 10px" :size="handleSize()">
    <el-table-column v-if="type === 'enroll'" align="center" :label="'报名记录'">
      <el-table-column loading="loading" label="ID" width="200px" sortable element-loading-text="请给我点时间！">
        <template v-slot="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

<!--      width="300px"-->
      <el-table-column sortable style="width: 20vw" label="学号">
        <template v-slot="scope">
          <span>{{ scope.row.number }}</span>
        </template>
      </el-table-column>

<!--      min-width="200px"-->
      <el-table-column  style="min-width: 20vw" label="姓名">
        <template v-slot="{row}">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>

<!--      width="300px"-->
      <el-table-column style="min-width: 20vw" label="学院">
        <template v-slot="scope">
          <span>{{ scope.row.college }}</span>
        </template>
      </el-table-column>

<!--      width="200px"-->
      <el-table-column class-name="status-col" label="状态" style="min-width: 20vw">
        <template v-slot="{row}">
          <el-tag :type="row.status | statusFilter">
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table-column>

    <el-table-column v-if="type === 'enter'" align="center" :label="'与会记录'">
      <el-table-column loading="loading" label="ID" width="200px" sortable element-loading-text="请给我点时间！">
        <template v-slot="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column sortable width="300px" label="学号">
        <template v-slot="scope">
          <span>{{ scope.row.number }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="200px" label="姓名">
        <template v-slot="{row}">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column width="300px" label="学院">
        <template v-slot="scope">
          <span>{{ scope.row.college }}</span>
        </template>
      </el-table-column>

      <el-table-column class-name="status-col" label="状态" width="200px">
        <template v-slot="{row}">
          <el-tag :type="row.status | statusFilter">
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table-column>
  </el-table>
</template>

<script>
import { fetchList } from '@/api/article'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  props: {
    type: {
      type: String,
      default: 'enroll'
    },
    data: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      title: '',
      list: null,
      listQuery: {
        page: 1,
        limit: 5,
        type: this.type,
        sort: '+id'
      },
      loading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.$emit('create') // for test
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.loading = false
      })
    },
    handleSize() {
      return this.$store.state.app.device === 'mobile' ? 'mini' : 'medium'
    }
  }
}
</script>


<style scoped lang="scss">
//.el-table{
//  font-size: 16px;
//  font-weight: 530;
//  font-family: "微软雅黑",serif;
//  letter-spacing: 1px;
//}
</style>

